def calc_kd_ratio(episode):
    killed = episode.get("battle_info", {}).get("enemy_killed", 0)
    dead = episode.get("battle_info", {}).get("allied_dead", 1)
    return killed / max(dead, 1)

def calc_win_rate(episodes):
    wins = [1 if ep.get("reward", [])[-1] > 0 else 0 for ep in episodes]
    return sum(wins) / len(wins)
